<template>
  <div class="main">
    <div class="router">
      <keep-alive>
        <router-view></router-view>
      </keep-alive>
    </div>
    <van-tabbar v-model="active">
      <van-tabbar-item v-for="(item, index) in tabbarData" :key="index" @click="switchTab(item.pathName, index)">
        <span>{{ item.name }}</span>
        <template #icon="props">
          <img :src="props.active ? item.active : item.inactive" />
        </template>
      </van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
import { tabbarData } from '@/js/data';
export default {
  name: "Main",
  data() {
    return {
      active: 0,
      tabbarData
    };
  },
  created() {
    if (this.$route.query.index) {
      this.active = Number(this.$route.query.index)
    }
  },
  methods: {
    switchTab(path, index) {
      if (path == "home") this.$router.push({ path: this.$store.state.activePath })
      else this.$router.push({ path, query: { index } })
    }
  }
};
</script>

<style lang="scss" scoped>
.router {
  height: 100vh;
}
</style>